'use strict';
App.execute('console', 'sidebar module loading', 1);

App.module('Sidebar', function(Sidebar, App, Backbone, Marionette, $, _){
   Sidebar.Item = Backbone.Model.extend({});
   Sidebar.ItemCollection = Backbone.Collection.extend({
      model: Sidebar.Item,
   });
     
   var items;
   var sidebarContainerView;
   
   var initializeItems = function(){
      items = new Sidebar.ItemCollection([
         { id: 1,  name: "First Item",    href: "#" },
         { id: 2,  name: "Second Item",   href: "#" },
         { id: 3,  name: "Third Item",    href: "#" },
         { id: 4,  name: "Fourth Item",   href: "#" },
         { id: 5,  name: "Fifth Item",    href: "#" },
         { id: 6,  name: "Sixth Item",    href: "#" },
         { id: 7,  name: "Seventh Item",  href: "#" },
         { id: 8,  name: "Eighth Item",   href: "#" },
         { id: 9,  name: "Ninth Item",    href: "#" },
         { id: 10, name: "Tenth Item",    href: "#" },
         { id: 11, name: "Eleventh Item", href: "#" },
         { id: 12, name: "Twelfth Item",  href: "#" }
      ]);
   };
     
   var API = {
      getItems: function(){
         if (items === undefined){
            initializeItems();
         }
         return items;
      }
   };
   
   App.reqres.setHandler("sidebar:items", function(){
      return API.getItems();
   });
   
   this.addInitializer(function(){
      App.execute('console', 'sidebar module started  .', 1);
      var items = App.request("sidebar:items");
      this.sidebarView = new App.SidebarContainerView({
         collection: items,
         predecessor: '#main-sidebar-container'
      });
      App.sidebarRegion.show(this.sidebarView);
      $('#main-sidebar').niceScroll({
         'horizrailenabled': false,
         'cursorcolor': '#bbb',
         'cursorwidth': 6,
         'cursorborder': '1px solid #eee',
         'bouncescroll': true,
         'railoffset': {left: 10 }
      });
   })
});

App.execute('console', 'sidebar module loaded', 1);